package com.shaw.workrecord.controller;

import com.shaw.workrecord.entity.PageResponse;
import com.shaw.workrecord.entity.ResponseBean;
import com.shaw.workrecord.pojo.request.FeedAddRequest;
import com.shaw.workrecord.pojo.request.FeedEditRequest;
import com.shaw.workrecord.pojo.request.FeedRecordPageRequest;
import com.shaw.workrecord.pojo.response.FeedResponse;
import com.shaw.workrecord.service.IFeedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiangjunhui
 * @description 喂养记录接口
 * @date 2023/8/10 14:51
 */
@Api(tags = {"喂养记录接口"})
@RestController
@Validated
public class FeedRecordController {

    @Autowired
    private IFeedService service;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "FeedRecordPageRequest", name = "request", value = "", required = true)
    })
    @ApiOperation(value = "喂养记录分页列表", notes = "", httpMethod = "GET")
    @GetMapping("/feedRecord")
    public ResponseBean<PageResponse<FeedResponse>> getPage(FeedRecordPageRequest request) {
        return ResponseBean.success(service.getFeedRecordPage(request));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "FeedAddRequest", name = "request", value = "", required = true)
    })
    @ApiOperation(value = "新增喂养记录", notes = "", httpMethod = "POST")
    @PostMapping("/feedRecord")
    public ResponseBean<Boolean> addRecord(@RequestBody FeedAddRequest request) {
        if (service.addFeedRecord(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("新增失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "FeedEditRequest", name = "request", value = "", required = true)
    })
    @ApiOperation(value = "编辑喂养记录", notes = "", httpMethod = "PUT")
    @PutMapping("/feedRecord")
    public ResponseBean<Boolean> editRecord(@RequestBody FeedEditRequest request) {
        if (service.editFeedRecord(request)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("编辑失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "删除喂养记录", notes = "", httpMethod = "DELETE")
    @DeleteMapping("/feedRecord/{id}")
    public ResponseBean<Boolean> deleteRecord(@PathVariable("id") Long id) {
        if (service.deleteFeedRecord(id)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("删除失败");
    }
}
